package org.zfes.snowier.cloud.zbss.cms.content.service;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.util.ZAssert;
import org.zfes.snowier.core.util.ZDateUtil;
import org.zfes.snowier.core.util.datex.ZDateStyle;
import org.springframework.web.multipart.MultipartFile;
import org.zfes.snowier.cloud.zbss.cms.content.dto.CmsContentCreateDto;
import org.zfes.snowier.cloud.zbss.cms.content.dto.CmsContentViewDto;
import org.zfes.snowier.cloud.zbss.cms.content.model.CmsContent;
import org.zfes.snowier.cloud.zbss.cms.model.dto.CmsModelDto;
import org.zfes.snowier.cloud.zbss.cms.model.model.CmsModelItem;
import org.zfes.snowier.cloud.zbss.cms.zconfig.ZConfig;
public interface ICmsContentService{

	 Optional<CmsContent> loadCmsContentById(Long id);
	 
	 void createCmsContent(CmsContentCreateDto contentCreateDto,Map<String ,String> userDefineAttrMap);
	
	 void updateCmsContent(CmsContent cmsContent);
	 void updateCmsContent(Long contentId,CmsContentCreateDto contentCreateDto,Map<String ,String> userDefineAttrMap);

	 void deleteCmsContent(Long id);
	
	 DataSet loadCmsContentDataSet(Map<String, Object> params);
	 Map<List<CmsContentViewDto>,Integer> loadCmsContentViewDtoByTagId(Long tagId);

 	void setCmsContentStatus(Long id, Byte status);

 	Long createCmsContent(CmsContent cmsContent);

	void updateAddViewCount(Long id, Integer countz);
	void updateAddFavoriteCount(Long id, Integer countz);
	void updateAddUpCount(Long id, Integer countz);
	void updateAddCommentCount(Long id, Integer countz);
	void updateAddForwardCount(Long id, Integer countz);
	void updateAddShareCount(Long id, Integer countz);
	void updateAddDownloadcount(Long id, Integer countz);
	
	
	default String generateLinkUrl(Long columnId,Long contentId) {
		String subPath=ZDateUtil.getNowStr(ZDateStyle.YYYYMMDD);
		return columnId+"/"+subPath+"/"+contentId+".html";
	}
	
	default void validateByModel(CmsModelDto cmsModelDto,CmsContent cmsContent,Map<String ,String> userDefineAttrMap) {
		//取出该模型下用户自定义字段列表
 		List<CmsModelItem> modelItemList = cmsModelDto.getCmsModelItemList();
		
 		//查看用户自定义的必填字段是否已填写
 		for(int i=0;i<modelItemList.size();i++) {
 			if(modelItemList.get(i).getIsRequired().equals(Byte.valueOf("1"))&&modelItemList.get(i).getIsColumn().equals(Byte.valueOf("2"))) {
 				ZAssert.isTrue(userDefineAttrMap.containsKey(modelItemList.get(i).getFieldLabel()), "请填写必填项");
 			}
 		}
	}
	
//	default String uploadColumnFile(MultipartFile file,Long columnId) {
//	 	
// 		FileAccessService fileAccessService = null ;
// 		FileParamInfo fileParamInfo = new FileParamInfo();
// 		
// 		//更新bizCode
// 		CmsContent content=loadCmsContentById(columnId).get();
// 		String contentCode=ZConfig.contentFilePath+content.getOrginName();
// 		fileParamInfo.setBizCode(contentCode);
// 		
//       //上传文件并返回需要的信息
//		FileResInfo fileResInfo=fileAccessService.upload(file,fileParamInfo);
// 		return fileResInfo.getFilePath();	
// 	}
	
	
	
	
}